<?php

namespace app\erp\controller;

use think\Controller;
use app\erp\model\Goodsdb;
use app\erp\model\Categorydb;
use app\erp\model\Branddb;
use app\erp\model\Memberdb;
use app\erp\model\Cartdb;
use app\erp\model\Shoppingdb;
use app\erp\model\Invoicedb;
use app\erp\model\Orderdb;
use app\erp\model\Returneddb;
use app\erp\model\Judgedb;
use app\erp\model\Visitdb;
use app\erp\model\Articledb;
use app\erp\model\Staffdb;
use app\erp\model\PriceRecorddb;
use app\erp\model\Adventdb;
use app\erp\model\Sitedb;
use app\erp\model\GoodsAccessorydb;
use app\erp\model\GoodsServicedb;
use app\api\model\Postdatadb;
use app\erp\model\PostNoticedb;
use app\erp\model\SalePricedb;
use app\erp\model\AttrValuedb;
use app\erp\model\Attrdb;
use app\erp\model\Artclassdb;
use think\Db;
 
class Api extends Controller
{
    public $config;
    public $request;
    public $post_domain = '';

    protected function _initialize()
    {
        header("Access-Control-Allow-Origin: *");
        header('Content-Type:application/json; charset=utf-8');
        $request = request();
        $this->request = $request->param();

        if (!isset ($request->param() ['config'])) {
            $this->layuiReturn('配置参数错误');
        }
        $this->config = $this->request ['config'];
        if (isset ($this->config ['is_app']) && $this->config ['is_app'] == true) {
            // $temp = explode('.', $this->config['package']);
            // $this->post_domain = $temp[1].'.'.$temp[0];
            $this->post_domain = $this->config ['post_domain'];
        } else {
            $server = $request->server();
            if (isset ($server ['HTTP_REFERER'])) {
                $HTTP_REFERER = $server ['HTTP_REFERER'];
                preg_match('/[\w][\w-]*\.(?:com\.cn|com|cn|co|net|org|gov|cc|biz|info)(\/|$)/isU', $HTTP_REFERER, $domain);
                $this->post_domain = str_replace('/', '', $domain [0]);
            }
        }
        $this->chkSign();
    }

    protected function ajaxReturn($data, $json_option = 0)
    {
        header('Content-Type:application/json; charset=utf-8');
        exit (json_encode($data, $json_option));
    }

    protected function layuiReturn($data, $count = 0, $msg = '', $code = 0)
    {
        $return ['data'] = $data;
        $return ['count'] = $count;
        $return ['msg'] = $msg;
        $return ['code'] = $code;
        if ($code == 0) {
            $return ['msg'] = $data;
        }
        $this->ajaxReturn($return);
    }

    protected function chkSign()
    {
        if (!isset ($this->config ['partnerId'])) {
            $this->layuiReturn('', 0, '', 0);
        }
        define('PARTNER_ID', $this->config ['partnerId']);

        if (isset ($this->config ['siteId']) && $this->config ['siteId'])
            define('SITE_ID', $this->config ['siteId']);
        else
            define('SITE_ID', null);
        if (isset ($this->config ['member_id']))
            define('MEMBER_ID', $this->config ['member_id']);
        else
            define('MEMBER_ID', 0);
        if ($this->post_domain != '') {
            //$this->chkApp();
        }
    }

    protected function chkApp()
    {
        $pwd = $this->config ['appId'] . $this->config ['appKey'];
        $data = $this->config ['appSecret'];
        $strArr = str_split(str_replace(array(
            'O0O0O',
            'o000o',
            'oo00o'
        ), array(
            '=',
            '+',
            '/'
        ), $data), 2);
        $strCount = count($strArr);
        foreach (str_split($pwd) as $key => $value)
            $key <= $strCount && isset ($strArr [$key]) && $strArr [$key] [1] === $value && $strArr [$key] = $strArr [$key] [0];
        $data = base64_decode(join('', $strArr));
        $temp = explode(',', $data);
        if (!in_array($this->post_domain, $temp)) {
            $this->layuiReturn('');
        }
    }

    // 校验会员是否登录状态
    protected function chkMemberIsLogin()
    {
        $memberdb = new Memberdb ();
        $get_member = $memberdb->memberInfo($this->request ['member_id']);
        if (count($get_member) == 0) {
            $this->layuiReturn('会员校验失败', 0, '会员登录超时', -101);
        }
        /*
         * $chk_login = $memberdb->chkOnline($this->request['member_id']);
         * if ($chk_login != 'success') {
         * $this->layuiReturn('会员已退出登录', 0, '会员登录超时', - 101);
         * }
         */
    }

    // 写接口输入日志
    public function savePostdata()
    {
        $postdatadb = new Postdatadb ();
        $postdatadb->param = $this->request;
        $postdatadb->ajaxSave();
        $this->layuiReturn($this->request ['param'], 1, 'success', 1);
    }

    // 设置分站token
    public function accessToken()
    {
        if (!isset ($this->request ['access_token'])) {
            $this->layuiReturn('参数错误');
        }
        $sitedb = new Sitedb ();
        $sitedb->param = $this->request;
        $sitedb->param ['site_id'] = $this->config ['siteId'];
        $data = $sitedb->ajaxSaveToken();
        $this->layuiReturn('success', 1, 'success', 1);
    }

    // 获取分站信息
    public function getSite()
    {
        $sitedb = new Sitedb ();
        $sitedb->param = $this->request;
        $data = $sitedb->ajaxFind($this->request ['site_id']);
        $this->layuiReturn($data, 1, 'success', 1);
    }

    // 获取分站token
    public function chkToken()
    {
        $sitedb = new Sitedb ();
        $sitedb->param ['site_id'] = $this->config ['siteId'];
        $data = $sitedb->ajaxChkToken($this->request ['token']);
        if ($data != 'success') {
            $this->layuiReturn($data, 0, $data, 0);
        } else {
            $this->layuiReturn('success', 0, 'success', 1);
        }
    }

    // 获取会员信息
    public function memberInfo()
    {
        if (!isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $memberdb = new Memberdb ();
        $get_member = $memberdb->memberInfo($this->request ['member_id']);
        $this->layuiReturn($get_member, 1, 'success', 1);
    }

    // 会员退出登录
    public function userLogout()
    {
        if (!isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        // $this->chkMemberIsLogin();
        $memberdb = new Memberdb ();
        $memberdb->param ['no_session'] = 'yes';
        $memberdb->logout($this->request ['member_id']);
        $this->layuiReturn('退出登录成功', 1, 'success', 1);
    }

    // 欢迎页
    public function index()
    {
        echo '欢迎使用';
    }

    // 产品列表
    public function goodsList()
    {
        $goodsdb = new Goodsdb ();
        if (isset ($this->request ['where'])) {
            foreach ($this->request ['where'] as $key => $val) {
                $goodsdb->param [$key] = $val;
            }
        }
        /*if (isset ($this->request ['sort'])) {
            $goodsdb->param ['_o'] = $this->request ['sort'] ['_o'];
            $goodsdb->param ['_b'] = $this->request ['sort'] ['_b'];
        }
        if (isset ($this->request ['page']) && isset ($this->request ['page'] ['page']) && isset ($this->request ['page'] ['limit'])) {
            $goodsdb->param ['page'] = $this->request ['page'] ['page'];
            $goodsdb->param ['limit'] = $this->request ['page'] ['limit'];
        } else {
            $this->layuiReturn('参数错误');
        }
        if (!isset ($this->request ['sale_state'])) {
            $goodsdb->param ['sale_state'] = 1;
        }
        if (isset ($this->request ['no_more_price'])) {
            $goodsdb->param ['no_more_price'] = 'yes';
        }
        if (!isset ($this->request ['no_need_audit_state'])) {
            $goodsdb->param ['audit_state'] = 1;
        }
        if (isset ($this->request ['no_need_handle_data'])) {
            $goodsdb->param ['no_need_handle_data'] = 'yes';
        }
        if (isset ($this->request ['need_cover'])) {
            $goodsdb->param ['need_cover'] = 'yes';
        }
        if (isset ($this->request ['need_attr'])) {
            $goodsdb->param ['need_attr'] = 'yes';
        }*/
        //$data = $goodsdb->ajaxFrontList();
        $data = $goodsdb->order($this->request ['sort'] ['_o'], $this->request ['sort'] ['_b'])
            ->page($this->request ['page'] ['page'], $this->request ['page'] ['limit'])
            ->field('goods_id,goods_sku,goods_name,goods_model,sale_price,sale_num,goods_picture,goods_pictures,jun_id')
            ->select()->append(['goods_image','zuidijia']);
        //halt($goodsdb->getLastSql());
        $this->layuiReturn($data, 100000, 'success', 1);
    }

    // 获取商品sku
    public function getGoodsSku()
    {
        $categorydb = new Categorydb ();
        $categorydb->param = $this->request;
        $get_category = $categorydb->ajaxTreeFind();
        $goodsdb = new Goodsdb ();
        $goodsdb->param ['category_sign'] = $get_category ['category_sign'];
        $get_sku = $goodsdb->ajaxSku();
        $this->layuiReturn($get_sku, count($get_sku), $get_category, 1);
    }

    // 多产品图片组
    public function goodsPicture()
    {
        $goodsdb = new Goodsdb ();
        $goodsdb->param = $this->request;
        $data = $goodsdb->pictureList();
        $this->layuiReturn($data, 1, 'success', 1);
    }

    // 分站产品价格
    public function goodsPrice()
    {
        $salePricedb = new SalePricedb ();
        $salePricedb->param = $this->request;
        $data = $salePricedb->ajaxList();
        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 商品属性
    public function goodsAttrValue()
    {
        $attrValuedb = new AttrValuedb ();
        $attrValuedb->param = $this->request;
        $attr_value = $attrValuedb->ajaxSelect($this->request ['goods_sku']);
        $attrdb = new Attrdb ();
        $goodsdb = new Goodsdb ();
        $get_goods = $goodsdb->ajaxFindField($this->request ['goods_sku'], $this->request ['site_id'], 'category_sign3');
        $attrdb->param = $this->request;
        $attrdb->param ['category_sign'] = $get_goods ['category_sign3'];
        $category_attr = $attrdb->ajaxList();
        $attr_arr = array();
        foreach ($category_attr as $k => $v) {
            $temp = array();
            $temp ['group_name'] = $v ['group_name'];
            $temp ['attr_name'] = $v ['attr_name'];
            $temp ['attr_value'] = isset ($attr_value [$v ['attr_sign']]) ? $attr_value [$v ['attr_sign']] : ' ';
            array_push($attr_arr, $temp);
        }
        $this->layuiReturn($attr_arr, count($attr_arr), 'success', 1);
    }

    // 添加河南产品
    public function addHenanGoods()
    {
        if (!isset ($this->request ['param'])) {
            $this->layuiReturn('参数错误');
        }
        $goodsdb = new Goodsdb ();
        $goodsdb->param = $this->request ['param'];
        $return = $goodsdb->ajaxSaveHenan();
        $goods_sku = $goodsdb->last_goods_sku;
        $this->layuiReturn($goods_sku, 1, $return, 1);
    }

    // 添加河南商品配件
    public function addHenanAccessory()
    {
        if (!isset ($this->request ['param'])) {
            $this->layuiReturn('参数错误');
        }
        $accessorydb = new GoodsAccessorydb ();
        $accessorydb->param = $this->request ['param'];
        $return = $accessorydb->ajaxSave();
        $this->layuiReturn('保存成功', 1, $return, 1);
    }

    // 添加河南商品服务
    public function addHenanService()
    {
        if (!isset ($this->request ['param'])) {
            $this->layuiReturn('参数错误');
        }
        $servicedb = new GoodsServicedb ();
        $servicedb->param = $this->request ['param'];
        $return = $servicedb->ajaxSave();
        $this->layuiReturn('保存成功', 1, $return, 1);
    }

    // 分类列表
    public function categoryList()
    {
        if (!isset ($this->request ['parent_sign'])) {
            $this->layuiReturn('参数错误');
        }
        $categorydb = new Categorydb ();
        $categorydb->param ['parent_sign'] = $this->request ['parent_sign'];
        $data = $categorydb->ajaxSelect($this->request ['parent_sign']);
        $this->layuiReturn($data ['data'], $data ['count'], 'success', 1);
    }

    // 分类树
    public function categoryAllTree()
    {
        $categorydb = new Categorydb ();
        $categorydb->param ['parent_sign'] = '0';
        $data = $categorydb->ajaxList();
        foreach ($data as $key => $val) {
            $categorydb->param ['parent_sign'] = $val ['category_sign'];
            $data [$key] ['two'] = $categorydb->ajaxList();
            foreach ($data [$key] ['two'] as $k => $v) {
                $categorydb->param ['parent_sign'] = $v ['category_sign'];
                $data [$key] ['two'] [$k] ['three'] = $categorydb->ajaxList();
            }
        }
        $this->layuiReturn($data, 1, 'success', 1);
    }

    // 第三级分类
    public function categoryThree()
    {
        $categorydb = new Categorydb ();
        $categorydb->param ['level'] = 3;
        $categorydb->param ['no_need_handle_data'] = 'no';
        $data = $categorydb->ajaxList();
        $this->layuiReturn($data, 1, 'success', 1);
    }

    // 根据第三方参数获取分类
    public function apiCategory()
    {
        $categorydb = new Categorydb ();
        $categorydb->param ['api_option'] = $this->request ['api_option'];
        $data = $categorydb->ajaxList();
        $this->layuiReturn($data, 1, 'success', 1);
    }

    // 分类品牌
    public function categoryBrandList()
    {
        if (!isset ($this->request ['category_sign'])) {
            $this->layuiReturn('参数错误');
        }
        $branddb = new Branddb ();
        $branddb->param ['category_sign'] = $this->request ['category_sign'];
        $branddb->param ['is_select'] = 'yes';
        $branddb->param ['page'] = 1;
        $branddb->param ['limit'] = 50;
        $branddb->param ['_o'] = 'brand_id';
        $branddb->param ['_b'] = 'desc';
        $data = $branddb->ajaxSelect();
        $this->layuiReturn($data ['data'], $data ['count'], 'success', 1);
    }

    public function goodsOnlyDetail()
    {
        if (!isset ($this->request ['goods_sku']) || !$this->request ['goods_sku'] || !isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误1');
        }
        $goodsdb = new Goodsdb ();
        $goodsdb->param ['goods_sku'] = $this->request ['goods_sku'];
        if (isset ($this->request ['api_get_add_set'])) {
            $goodsdb->param ['api_get_add_set'] = $this->request ['api_get_add_set'];
        }
        if (isset ($this->request ['no_more_price'])) {
            $goodsdb->param ['no_more_price'] = 'yes';
        }
        if (isset ($this->request ['no_need_goods_handle'])) {
            $goodsdb->param ['no_need_goods_handle'] = 'yes';
        }
        if (isset ($this->request ['no_need_attr'])) {
            $goodsdb->param ['no_need_attr'] = 'yes';
        }
        $data = $goodsdb->ajaxFind();
        $this->layuiReturn($data, 1, 'success', 1);
        if (!isset ($data ['goods_id'])) {
            $this->layuiReturn('参数错误');
        }
        $this->layuiReturn($data, 1, 'success', 1);
    }

    // 产品详情
    public function goodsDetail()
    {
        if (!isset ($this->request ['goods_sku']) || !$this->request ['goods_sku'] || !isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误1');
        }
        $goodsdb = new Goodsdb ();
        $goodsdb->param ['goods_sku'] = $this->request ['goods_sku'];
        $goodsdb->param['no_need_picture'] = 'yes';

        $data = $goodsdb->ajaxFind();

        if (!isset ($data ['goods_id'])) {
            $this->layuiReturn('参数错误');
        }
        $goodsdb->param ['audit_state'] = $data ['audit_state'];
        $goodsdb->param ['sale_state'] = $data ['sale_state'];
        $goodsdb->param ['is_copy'] = $data ['is_copy'];
        $goodsdb->param ['is_real'] = $data ['is_real'];
        $goodsdb->param ['is_shopping'] = $data ['is_shopping'];
        $goodsdb->param ['is_install'] = $data ['is_install'];
        $goodsdb->aloneSave([
            'view_times' => $data ['view_times'] + 1
        ], [
            'goods_id' => $data ['goods_id']
        ]);
        if ($this->request ['member_id']) {
            $visitdb = new Visitdb ();
            $visitdb->param ['member_id'] = $this->request ['member_id'];
            $visitdb->param ['goods_sku'] = $data ['goods_sku'];
            $visitdb->ajaxSave();
        }
        // 品牌信息
        $branddb = new Branddb ();
        $branddb->param ['brand_sign'] = $data ['brand_sign'];
        $get_brand_info = $branddb->ajaxFind($data ['brand_sign']);
        $data ['brand_info'] = $get_brand_info;
        // 该品牌的产品数量
        /*$goodsdb->param = array();
        $goodsdb->param ['brand_sign'] = $data ['brand_sign'];
        $brand_goods_count = $goodsdb->ajaxCount();
        $data ['brand_goods_count'] = $brand_goods_count;*/
        // 该品牌推荐产品4条
        /*$goodsdb->param = array ();
        $goodsdb->param ['brand_sign'] = $data ['brand_sign'];
        $goodsdb->param ['_o'] = 'sale_num';
        $goodsdb->param ['_b'] = 'desc';
        $goodsdb->param ['page'] = 1;
        $goodsdb->param ['limit'] = 4;
        if (isset ( $this->config ['is_app'] )) {
            $goodsdb->param ['limit'] = 8;
        }
        $brand_goods_list = $goodsdb->ajaxList ();
        */
        /*$brand_goods_list = Db::name('goods')
            ->where('brand_sign', $data['brand_sign'])
            ->where('sale_state',1)
            ->field('goods_id,goods_sku,goods_name,goods_model,sale_price,sale_num')
            ->order('sale_num desc')
            ->limit(isset ($this->config ['is_app']) ? 8 : 4)
            ->select();*/
        $goodsdb->param = [];
        $goodsdb->param['brand_sign'] = $data['brand_sign'];
        $goodsdb->param['sale_state'] = 1;
        $goodsdb->param['_o'] = 'sale_num';
        $goodsdb->param['_b'] = 'desc';
        $goodsdb->param['limit'] = isset ($this->config ['is_app']) ? 8 : 4;
        $goodsdb->param['page'] = 1;
        $brand_goods_list = $goodsdb->ajaxFrontList();
        $data ['brand_goods_list'] = $brand_goods_list;
        $this->layuiReturn($data, 1, 'success', 1);
    }

    // 用户登录
    public function userLogin()
    {
        $memberdb = new Memberdb ();
        $memberdb->param ['username'] = $this->request ['username'];
        $memberdb->param ['password'] = $this->request ['password'];
        $memberdb->param ['no_session'] = 'yes';
        $chk_member = $memberdb->ajaxFind();
        if ($chk_member != 'fail') {
            $memberdb->login($chk_member ['member_id']);
            $return ['member_id'] = $chk_member ['member_id'];
            $return ['username'] = $chk_member ['username'];
            $return ['phone'] = $chk_member ['phone'];
            $this->layuiReturn($return, 1, '', 1);
        } else {
            $this->layuiReturn('登录账号或密码错误');
        }
    }

    // 会员注册
    public function userRegister()
    {
        if ($this->request ['password'] != $this->request ['chk_password']) {
            $this->layuiReturn('两次密码不一致');
        }
        $memberdb = new Memberdb ();
        $memberdb->param ['username'] = $this->request ['username'];
        $memberdb->param ['password'] = $this->request ['password'];
        $memberdb->param ['site_id'] = $this->config ['siteId'];
        $memberdb->param ['partner_id'] = $this->config ['partnerId'];
        $return = $memberdb->ajaxSave();
        if ($return == 'success') {
            $this->layuiReturn('注册成功', 1, '注册成功', 1);
        } else {
            $this->layuiReturn($return);
        }
    }

    // 添加购物车
    public function addCartArr()
    {
        // $this->chkMemberIsLogin();
        $cartdb = new Cartdb ();
        $cartdb->param ['order_no'] = '';
        $cartdb->param ['cart_info'] = $this->request ['cart_info'];
        $return_msg = $cartdb->addCartNoChkgoods();
        if ($return_msg == 'success') {
            $this->layuiReturn('', 0, 'success', 1);
        } else {
            $this->layuiReturn($return_msg);
        }
    }

    // 添加购物车
    public function addCart()
    {
        if (!isset ($this->request ['goods_sku']) || !isset ($this->request ['buy_num']) || !isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        // $this->chkMemberIsLogin();
        $cartdb = new Cartdb ();
        $cart_info_arr [0] ['goods_sku'] = $this->request ['goods_sku'];
        $cart_info_arr [0] ['sale_attr'] = '';
        $cart_info_arr [0] ['sale_attr_html'] = '';
        $cart_info_arr [0] ['num'] = $this->request ['buy_num'];
        $cart_info_arr [0] ['member_id'] = $this->request ['member_id'];
        $cartdb->param ['order_no'] = '';
        $cartdb->param ['cart_info'] = $cart_info_arr;
        if (isset ($this->request ['set_sale_price'])) {
            $cartdb->param ['set_sale_price'] = 'sale_price';
        }

        if (isset ($this->request ['no_need_goods_handle'])) {
            $cartdb->param ['no_need_goods_handle'] = 'yes';
        }
        if (isset ($this->request ['no_need_attr'])) {
            $cartdb->param ['no_need_attr'] = 'yes';
        }
        $return_msg = $cartdb->addCart();
        if ($return_msg == 'success') {
            $this->layuiReturn('', 0, 'success', 1);
        } else {
            $this->layuiReturn($return_msg);
        }
    }

    // 获取购物车数量
    public function getCartNum()
    {
        if (!isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        $cartdb = new Cartdb ();
        $cartdb->param ['order_no'] = '';
        $cartdb->param ['member_id'] = $this->request ['member_id'];
        $num = $cartdb->getCartNum();
        $this->layuiReturn($num, $num, 'success', 1);
    }

    // 获取购物车列表
    public function getCartList()
    {
        if (!isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        // $this->chkMemberIsLogin();
        $cartdb = new Cartdb ();
        $cartdb->param ['order_no'] = '';
        $cartdb->param ['member_id'] = $this->request ['member_id'];
        $cartdb->param ['need_goods_info'] = 'yes';
        $cartdb->param ['no_need_attr'] = 'yes';
        $cartdb->param ['no_need_goods_handle'] = 'yes';
        $cartdb->param ['need_cover'] = 'yes';
        if (isset ($this->request ['only_checked']) && $this->request ['only_checked'] == 'yes') {
            $cartdb->param ['is_checked'] = 1;
        }
        $data = $cartdb->ajaxList();
        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 获取订单下的购物车信息
    public function orderCartList()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['order_no'])) {
            $this->layuiReturn('参数错误');
        }
        $cartdb = new Cartdb ();
        $cartdb->param ['order_no'] = $this->request ['order_no'];
        $cartdb->param ['member_id'] = $this->request ['member_id'];
        if (isset ($this->request ['need_goods_title'])) {
            $cartdb->param ['need_goods_title'] = 'yes';
        }
        if (isset ($this->request ['need_goods_info']) && $this->request ['need_goods_info'] == 'yes') {
            $cartdb->param ['need_goods_info'] = 'yes';
        }
        $data = $cartdb->ajaxList();
        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 设置购物车是否结算状态
    public function setCartSelect()
    {
        if (!isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $cartdb = new Cartdb ();
        $cartdb->param ['order_no'] = '';
        $cartdb->param ['member_id'] = $this->request ['member_id'];
        if (isset ($this->request ['no_checked']) && $this->request ['no_checked']) {
            $save_data = array(
                'is_checked' => 2
            );
            $cart_ids = $this->request ['no_checked'];
            $cartdb->aloneSave($save_data, $cart_ids);
        }
        if (isset ($this->request ['yes_checked']) && $this->request ['yes_checked']) {
            $save_data = array(
                'is_checked' => 1
            );
            $cart_ids = $this->request ['yes_checked'];
            $cartdb->aloneSave($save_data, $cart_ids);
        }
        if (!isset ($this->request ['no_back'])) {
            $this->getCartList();
        } else {
            $this->layuiReturn('成功', 1, 'success', 1);
        }
    }

    // 修改购物车数量
    public function modifyCartNum()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['cart_id']) || !isset ($this->request ['num'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $cartdb = new Cartdb ();
        $cartdb->param ['order_no'] = '';
        $cartdb->param ['member_id'] = $this->request ['member_id'];
        if ($this->request ['num'] && is_numeric($this->request ['num']) && $this->request ['num'] > 0) {
            $save_data = array(
                'goods_num' => $this->request ['num']
            );
            $cart_ids = $this->request ['cart_id'];
            $cartdb->aloneSave($save_data, $cart_ids);
        }
        if (!isset ($this->request ['no_back'])) {
            $this->getCartList();
        } else {
            $this->layuiReturn('成功', 1, 'success', 1);
        }
    }

    // 删除购物车产品
    public function delCartInfo()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['cart_id'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $cartdb = new Cartdb ();
        $cartdb->param ['order_no'] = '';
        $cartdb->param ['member_id'] = $this->request ['member_id'];
        $cartdb->param ['cart_id'] = $this->request ['cart_id'];
        $cartdb->ajaxDelete();
        unset ($cartdb->param ['cart_id']);
        $this->getCartList();
    }

    // 获取会员配送地址列表
    public function getAddressList()
    {
        if (!isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        // $this->chkMemberIsLogin();
        $shoppingdb = new Shoppingdb ();
        $shoppingdb->param = $this->request;
        $data = $shoppingdb->ajaxSelect();
        $this->layuiReturn($data ['data'], $data ['count'], 'success', 1);
    }

    // 保存配送地址
    public function saveAddress()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['field'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $shoppingdb = new Shoppingdb ();
        $shoppingdb->param = $this->request ['field'];
        $shoppingdb->param ['member_id'] = $this->request ['member_id'];
        $data = $shoppingdb->ajaxSave();
        if ($data == 'success') {
            $this->getAddressList();
        } else {
            $this->layuiReturn($data, 0, $data, 0);
        }
    }

    // 保存配送地址
    public function saveApiAddress()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['field'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $shoppingdb = new Shoppingdb ();
        $shoppingdb->param = $this->request ['field'];
        $shoppingdb->param ['member_id'] = $this->request ['member_id'];
        $data = $shoppingdb->ajaxSave();
        if ($data == 'success') {
            return $shoppingdb->last_id;
        } else {
            $this->layuiReturn($data, 0, $data, 0);
        }
    }

    // 获取会员配送地址信息
    public function getAddressInfo()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['address_id'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $shoppingdb = new Shoppingdb ();
        $shoppingdb->param ['member_id'] = $this->request ['member_id'];
        $shoppingdb->param ['shopping_id'] = $this->request ['address_id'];
        $data = $shoppingdb->ajaxFind();
        if ($data) {
            $this->layuiReturn($data, 1, 'success', 1);
        } else {
            $this->layuiReturn('参数错误');
        }
    }

    // 获取最新录入的地址
    public function getAddressNew()
    {
        if (!isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $shoppingdb = new Shoppingdb ();
        $shoppingdb->param ['member_id'] = $this->request ['member_id'];
        $data = $shoppingdb->ajaxApiFind();
        if ($data) {
            $this->layuiReturn($data, 1, 'success', 1);
        } else {
            $this->layuiReturn('参数错误');
        }
    }

    // 设置配送地址是否默认状态
    public function setAddressDefault()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['address_id'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $shoppingdb = new Shoppingdb ();
        $shoppingdb->param ['member_id'] = $this->request ['member_id'];
        $shoppingdb->param ['shopping_id'] = $this->request ['address_id'];
        $data = $shoppingdb->setDefault();
        if ($data == 'success') {
            unset ($shoppingdb->param ['shopping_id']);
            $this->getAddressList();
        } else {
            $this->layuiReturn('参数错误' . $data);
        }
    }

    // 删除配送地址
    public function delAddress()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['address_id'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $shoppingdb = new Shoppingdb ();
        $shoppingdb->param ['member_id'] = $this->request ['member_id'];
        $shoppingdb->param ['shopping_id'] = $this->request ['address_id'];
        $shoppingdb->ajaxDelete();
        unset ($shoppingdb->param ['shopping_id']);
        $this->getAddressList();
    }

    // 开票
    public function addInvoice()
    {
        if (!isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        $invoicedb = new Invoicedb ();
        $invoicedb->param = $this->request;
        $invoicedb->ajaxSave();
        $this->ajaxReturn('success', 1);
    }

    // 获取发票信息
    public function getLastInvoice()
    {
        if (!isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $invoicedb = new Invoicedb ();
        $invoicedb->param ['member_id'] = $this->request ['member_id'];
        $data = $invoicedb->ajaxFind();
        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 获取订单发票
    public function getInvoiceInfo()
    {
        if (!isset ($this->request ['order_no'])) {
            $this->layuiReturn('参数错误');
        }
        // $this->chkMemberIsLogin();
        $invoicedb = new Invoicedb ();
        $invoicedb->param ['order_no'] = $this->request ['order_no'];
        $data = $invoicedb->ajaxFind();
        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 创建订单
    public function createOrder()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['order_info'])) {
            $this->layuiReturn('参数错误');
        }
        // $this->chkMemberIsLogin();
        $cartdb = new Cartdb ();
        $cartdb->param ['order_no'] = '';
        $cartdb->param ['member_id'] = $this->request ['member_id'];
        $cartdb->param ['is_checked'] = 1;

        $cart_info = $cartdb->ajaxList();
        $cart_goods_ids = $cart_info ['cart_ids'];
        $cart_ids = $cart_info ['cart_id_arr'];
        $sum_price = $cart_info ['sum_price'];
        $cart_json = $cart_info ['json_data'];
        $orderdb = new Orderdb ();
        switch ($this->request ['order_info'] ['pay_type']) {
            case 'zhangqi' :
                $pay_type = 3;
                break;
            case 'cash' :
                $pay_type = 1;
                break;
            case 'yinhang' :
                $pay_type = 4;
                break;
            default :
                $pay_type = 2;
                break;
        }
        $this->request ['order_info'] ['pay_type'] = $pay_type;
        $this->request ['order_info'] ['member_id'] = $this->request ['member_id'];
        if (!isset ($this->request ['order_info'] ['order_money'])) {
            $this->request ['order_info'] ['order_money'] = $sum_price * 100;
        }
        $this->request ['order_info'] ['cart_ids'] = $cart_ids;

        $orderdb->param = $this->request ['order_info'];
        $return = $orderdb->addOrder();
        if ($return == 'success') {
            $this->layuiReturn($orderdb->last_order_no, 0, 'success', 1);
        } else {
            $this->layuiReturn($return);
        }
    }

    // 确认订单
    public function confirmOrder()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['order_no'])) {
            $this->layuiReturn('参数错误');
        }
        // $this->chkMemberIsLogin();
        $orderdb = new Orderdb ();
        $orderdb->param ['event'] = 'edit_state';
        $orderdb->param ['post_data'] = array(
            'order_state' => 2
        );
        $orderdb->param ['member_id'] = $this->request ['member_id'];
        $orderdb->param ['order_no'] = $this->request ['order_no'];
        $data = $orderdb->editOrder();
        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 修改订单发票状态
    public function editOrderInvoice()
    {
        $orderdb = new Orderdb ();
        $orderdb->param ['order_no'] = $this->request ['order_no'];
        $data = $orderdb->ajaxSaveInvoiceState();
        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 订单状态统计
    public function orderStateCount()
    {
        if (!isset ($this->request ['member_id'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $orderdb = new Orderdb ();
        $orderdb->param ['member_id'] = $this->request ['member_id'];
        $data = $orderdb->ajaxStateCount();
        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 获取订单列表
    public function getOrderList()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['page']) || !isset ($this->request ['limit'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $orderdb = new Orderdb ();
        if (isset ($this->request ['where'])) {
            $orderdb->param = $this->request ['where'];
        }
        $orderdb->param ['member_id'] = $this->request ['member_id'];
        $orderdb->param ['page'] = $this->request ['page'];
        $orderdb->param ['limit'] = $this->request ['limit'];
        $orderdb->param ['_o'] = 'order_id';
        $orderdb->param ['_b'] = 'desc';
        $orderdb->param ['need_goods_info'] = 'yes';
        $orderdb->param ['need_cart'] = 'yes';
        $data = $orderdb->ajaxSelect();
        $this->layuiReturn($data ['data'], $data ['count'], 'success', 1);
    }

    // 获取订单详情
    public function getOrderDetail()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['order_no'])) {
            $this->layuiReturn('参数错误');
        }
        // $this->chkMemberIsLogin();
        $orderdb = new Orderdb ();
        $orderdb->param ['order_no'] = $this->request ['order_no'];
        $orderdb->param ['member_id'] = $this->request ['member_id'];
        if (!isset ($this->request ['need_goods_info'])) {
            $orderdb->param ['need_goods_info'] = 'yes';
        }
        if (!isset ($this->request ['need_express_info'])) {
            $orderdb->param ['need_express_info'] = 'yes';
        }
        if (isset ($this->request ['no_need_invoice'])) {
            $orderdb->param ['no_need_invoice'] = 'yes';
        }
        if (isset ($this->request ['no_need_goods_handle'])) {
            $orderdb->param ['no_need_goods_handle'] = 'yes';
        }
        if (isset ($this->request ['no_more_price'])) {
            $orderdb->param ['no_more_price'] = 'yes';
        }
        $orderdb->param['need_cart'] = 'yes';
        $data = $orderdb->ajaxFind();
        $this->layuiReturn($data, 1, 'success', 1);
    }

    // 确定订单收货
    public function confirmReceiving()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['pack_id']) || !isset ($this->request ['order_no'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $orderdb = new Orderdb ();
        $orderdb->param ['event'] = 'edit_state';
        $orderdb->param ['post_data'] ['order_state'] = 4;
        $orderdb->param ['post_data'] ['express_id'] = $this->request ['pack_id'];
        $orderdb->param ['post_data'] ['member_id'] = $this->request ['member_id'];
        $orderdb->param ['order_no'] = $this->request ['order_no'];
        $data = $orderdb->editOrder();
        $this->getOrderDetail();
    }

    // 订单申请退换货
    public function returnedGoods()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['returned_info'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $returneddb = new Returneddb ();
        $returneddb->param = $this->request ['returned_info'];
        $returneddb->ajaxSave();
        $cartdb = new Cartdb ();
        $cartdb->param ['order_no'] = $this->request ['returned_info'] ['order_no'];
        $cartdb->param ['goods_sku'] = $this->request ['returned_info'] ['goods_sku'];
        if ($this->request ['returned_info'] ['returned_type'] == 1) {
            // 退货
            $cartdb->param ['returned_state'] = 2;
        } else {
            $cartdb->param ['returned_state'] = 4;
        }
        $cartdb->setReturned();
        $this->request ['order_no'] = $this->request ['returned_info'] ['order_no'];
        $this->getOrderDetail();
    }

    // 第三方订单申请退换货
    public function returnedGoodsThrid()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['returned_info'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $returneddb = new Returneddb ();
        $returneddb->param = $this->request ['returned_info'];
        $returneddb->ajaxSave();
        $cartdb = new Cartdb ();
        $cartdb->param ['order_no'] = $this->request ['returned_info'] ['order_no'];
        $cartdb->param ['goods_sku'] = $this->request ['returned_info'] ['goods_sku'];
        if ($this->request ['returned_info'] ['returned_type'] == 1) {
            // 退货
            $cartdb->param ['returned_state'] = 2;
        } else {
            $cartdb->param ['returned_state'] = 4;
        }
        $cartdb->setReturned();
        $this->layuiReturn('success', 1, 'success', 1);
    }

    // 评价订单产品
    public function sendJudge()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['judge_info'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $judgedb = new Judgedb ();
        $judgedb->param = $this->request ['judge_info'];
        $judgedb->param ['member_id'] = $this->request ['member_id'];
        $return = $judgedb->ajaxSave();
        if ($return != 'success') {
            $this->layuiReturn($return);
        } else {
            $this->layuiReturn('success', 1, 'success', 1);
        }
    }

    // 验证订单产品是否可进行评价
    public function checkJudgeCommit()
    {
        if (!isset ($this->request ['goods_sku']) || !isset ($this->request ['cart_id'])) {
            $this->layuiReturn('参数错误');
        }
        if ($this->request ['cart_id'] == '') {
            $this->layuiReturn('success', 1, 'success', 1);
        }
        if ($this->request ['member_id'] == '') {
            $this->layuiReturn('success', 1, 'success', 1);
        }
        $cartdb = new Cartdb ();
        $cartdb->param ['member_id'] = $this->request ['member_id'];
        $cartdb->param ['cart_id'] = $this->request ['cart_id'];
        $cartdb->param ['goods_sku'] = $this->request ['goods_sku'];
        $get_cart_count = $cartdb->ajaxCount();
        if ($get_cart_count == 0) {
            $this->layuiReturn('success', 1, 'success', 1);
        }
        $judgedb = new Judgedb ();
        $judgedb->param ['cart_id'] = $this->request ['cart_id'];
        $judgedb->param ['member_id'] = $this->request ['member_id'];
        $judgedb->param ['goods_sku'] = $this->request ['goods_sku'];
        $chk_judge_count = $judgedb->ajaxCount();
        if ($chk_judge_count == 0) {
            $this->layuiReturn('success', 0, 'success', 1);
        } else {
            $this->layuiReturn('success', 1, 'success', 1);
        }
    }

    // 商品价格历史记录
    public function goodsPriceRecord()
    {
        if (!isset ($this->request ['goods_sku']) || !isset ($this->request ['get_price_type'])) {
            $this->layuiReturn('参数错误');
        }
        if (!in_array($this->request ['get_price_type'], array(
            'get_market_price',
            'get_sale_price',
            'get_api_price'
        ))) {
            $this->layuiReturn('价格记录参数错误');
        }
        $priceRecorddb = new PriceRecorddb ();
        $priceRecorddb->param ['site_id'] = $this->config ['siteId'];
        $priceRecorddb->param ['goods_sku'] = $this->request ['goods_sku'];
        $priceRecorddb->param ['get_price_type'] = $this->request ['get_price_type'];
        $data = $priceRecorddb->ajaxSelect();
        $this->layuiReturn($data, 1, 'success', 1);
    }

    // 商品评价列表
    public function judgeList()
    {
        if (!isset ($this->request ['goods_sku']) || !isset ($this->request ['page']) || !isset ($this->request ['limit'])) {
            $this->layuiReturn('参数错误');
        }
        $judgedb = new Judgedb ();
        $judgedb->param ['goods_sku'] = $this->request ['goods_sku'];
        if (isset ($this->request ['judge_star'])) {
            $judgedb->param ['judge_star'] = $this->request ['judge_star'];
        }
        $judgedb->param ['page'] = $this->request ['page'];
        $judgedb->param ['limit'] = $this->request ['limit'];
        $data = $judgedb->ajaxSelect();
        $this->layuiReturn($data ['data'], $data ['count'], 'success', 1);
    }

    // 访问产品历史记录
    public function visitList()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['limit'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $visitdb = new Visitdb ();
        $visitdb->param ['member_id'] = $this->request ['member_id'];
        $visitdb->param ['limit'] = $this->request ['limit'];
        $get_goods_skus = $visitdb->getVisitGoodsSkus();
        $goodsdb = new Goodsdb ();
        $goodsdb->param ['goods_sku'] = $get_goods_skus;
        $goodsdb->param ['_o'] = 'goods_id';
        $goodsdb->param ['_b'] = 'desc';
        $goodsdb->param ['page'] = 1;
        $goodsdb->param ['limit'] = $this->request ['limit'];
        $goodsdb->param['sale_state'] = 1;
        //$data = $goodsdb->ajaxFrontList();
        $data = $goodsdb->order('goods_id desc')
            ->limit($this->request ['limit'])
            ->field('goods_id,goods_sku,goods_name,goods_model,sale_price,sale_num,goods_picture,goods_pictures,jun_id')
            ->select()->append(['goods_image']);

        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 取消订单
    public function cancelOrder()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['order_no'])) {
            $this->layuiReturn('参数错误');
        }
        // $this->chkMemberIsLogin();
        $orderdb = new Orderdb ();
        $orderdb->param ['order_no'] = $this->request ['order_no'];
        $orderdb->param ['event'] = 'edit_state';
        $orderdb->param ['post_data'] ['order_state'] = -1;
        $orderdb->param ['post_data'] ['cancel_type'] = 1;
        $orderdb->editOrder();
        $this->layuiReturn('取消成功', 1, 'success', 1);
    }

    // 获取文章分类
    public function artClass()
    {
        $artclassdb = new Artclassdb ();
        $artclassdb->param ['_o'] = 'artclass_id';
        $artclassdb->param ['_b'] = 'asc';
        $artclassdb->param ['page'] = 1;
        $artclassdb->param ['limit'] = 10;
        $data = $artclassdb->ajaxList();
        if (isset ($this->request ['son_art'])) {
            $articledb = new Articledb ();
            $articledb->param ['page'] = 1;
            $articledb->param ['limit'] = 12;
            $articledb->param ['no_need_picture'] = 'yes';
            foreach ($data as $key => $val) {
                $articledb->param ['artclass_id'] = $val ['artclass_id'];
                $data [$key] ['article_list'] = $articledb->ajaxList();
            }
        }
        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 文章列表
    public function artList()
    {
        if (!isset ($this->request ['artclass_id'])) {
            $this->layuiReturn('参数错误');
        }
        $articledb = new Articledb ();
        $articledb->param ['artclass_id'] = $this->request ['artclass_id'];
        $articledb->param ['page'] = isset ($this->request ['page']) ? $this->request ['page'] : 1;
        $articledb->param ['limit'] = isset ($this->request ['limit']) ? $this->request ['limit'] : 12;
        $data = $articledb->ajaxSelect();
        $this->layuiReturn($data ['data'], $data ['count'], 'success', 1);
    }

    // 文章信息
    public function artInfo()
    {
        if (!isset ($this->request ['article_id'])) {
            $this->layuiReturn('参数错误');
        }
        $articledb = new Articledb ();
        $articledb->param ['article_id'] = $this->request ['article_id'];
        $data = $articledb->ajaxFind();
        $this->layuiReturn($data, count($data), 'success', 1);
    }

    // 修改用户密码
    public function modifyPassword()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['old_password']) || !isset ($this->request ['new_password'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $memberdb = new Memberdb ();
        $memberdb->param ['member_id'] = $this->request ['member_id'];
        $memberdb->param ['password'] = $this->request ['old_password'];
        $memberdb->param ['new_password'] = $this->request ['new_password'];
        $return = $memberdb->modifyPassword();
        if ($return != 'success') {
            $this->layuiReturn($return);
        } else {
            $this->layuiReturn('密码修改成功', 1, 'success', 1);
        }
    }

    // 修改用户信息
    public function modifyUserInfo()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['modify_info'])) {
            $this->layuiReturn('参数错误');
        }
        $this->chkMemberIsLogin();
        $staffdb = new Staffdb ();
        $staffdb->param = $this->request ['modify_info'];
        $staffdb->param ['member_id'] = $this->request ['member_id'];
        $return = $staffdb->ajaxSave();
        if ($return == 'success') {
            $this->layuiReturn('信息修改成功', 1, 'success', 1);
        } else {
            $this->layuiReturn($return);
        }
    }

    // 上传用户头像
    public function uploadHead()
    {
        if (!isset ($this->request ['member_id']) || !isset ($this->request ['base64_file'])) {
            $this->layuiReturn('参数错误');
        }
        $file_url = $this->upload_base64($this->request ['base64_file']);
        $staffdb = new Staffdb ();
        $staffdb->param ['head_pic_url'] = $file_url;
        $staffdb->param ['member_id'] = $this->request ['member_id'];
        $return = $staffdb->ajaxSave();
        if ($return == 'success') {
            $this->layuiReturn('上传成功', 1, 'success', 1);
        } else {
            $this->layuiReturn($return);
        }
    }

    // 广告列表
    public function adventList()
    {
        if (!isset ($this->request ['adsense_id'])) {
            $this->layuiReturn('参数错误');
        }
        $adventdb = new Adventdb ();
        $adventdb->param ['adsense_id'] = $this->request ['adsense_id'];
        $adventdb->param ['page'] = isset ($this->request ['page']) ? $this->request ['page'] : 1;
        $adventdb->param ['limit'] = isset ($this->request ['limit']) ? $this->request ['limit'] : 50;
        $data = $adventdb->ajaxSelect();
        $this->layuiReturn($data ['data'], $data ['count'], 'success', 1);
    }

    // 推送消息
    public function postNoticeList()
    {
        $postNoticedb = new PostNoticedb ();
        $postNoticedb->param = $this->request;
        $data = $postNoticedb->ajaxSelect();
        $this->layuiReturn($data, 1, 'success', 1);
    }

    // 删除推送消息
    public function postNoticeDelete()
    {
        $postNoticedb = new PostNoticedb ();
        $postNoticedb->param = $this->request;
        $postNoticedb->ajaxDelete();
        $this->layuiReturn('success', 1, 'success', 1);
    }

    // base64上传
    protected function upload_base64($base64)
    {
        $base64_image = str_replace(' ', '+', $base64);
        if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image, $result)) {
            // 匹配成功
            if ($result [2] == 'jpeg') {
                $image_name = uniqid() . '.jpg';
                // 纯粹是看jpeg不爽才替换的
            } else {
                $image_name = uniqid() . '.' . $result [2];
            }
            $image_file = "./uploads/Personal/{$image_name}";
            // 服务器文件存储路径
            if (file_put_contents($image_file, base64_decode(str_replace($result [1], '', $base64_image)))) {
                return './uploads/Personal/' . $image_name;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}